package dao;

import org.apache.ibatis.annotations.*;
import pojo.UserRole;

import java.util.List;

@Mapper
public interface UserRoleMapper {

    @Select("SELECT * FROM user_role")
    @Results({
            @Result(column = "role_id", property = "roleId"),
            @Result(column = "role_name", property = "roleName")
    })
    List<UserRole> findAll();

    @Select("SELECT * FROM user_role WHERE role_id = #{roleId}")
    @Results({
            @Result(column = "role_id", property = "roleId"),
            @Result(column = "role_name", property = "roleName")
    })
    UserRole findById(String roleId);

    @Insert("INSERT INTO user_role(role_id, role_name) VALUES(#{roleId}, #{roleName})")
    int addRole(UserRole role);

    @Update("UPDATE user_role SET role_name = #{roleName} WHERE role_id = #{roleId}")
    int updateRole(UserRole role);

    @Delete("DELETE FROM user_role WHERE role_id = #{roleId}")
    int deleteRole(String roleId);
}